package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "sku后台管理接口")
@RequestMapping("admin/product/")
public class SkuManageController {
    @Autowired
    SkuInfoService skuInfoService;

    @PostMapping("saveSkuInfo")
    public Result save(@RequestBody SkuInfo skuInfo) {

        skuInfoService.save(skuInfo);
        return Result.ok();
    }


    //list/1/10
    @GetMapping("list/{page}/{limit}")
    @ApiOperation(value = "分页查询sku list")
    public Result save(@PathVariable Long page, @PathVariable Long limit) {

        return Result.ok(skuInfoService.getSkuInfoList(new Page<>(page, limit)));
    }

    // 下 架
    // http://localhost/admin/product/cancelSale/33
    @GetMapping("cancelSale/{skuId}")
    @ApiOperation(value = "分页查询sku list")
    public Result cancelSale(@PathVariable Long skuId) {
        skuInfoService.cancelSale(skuId);
        return Result.ok();
    }



    //上架
    // http://localhost/admin/product/onSale/44
    @GetMapping("onSale/{skuId}")
    @ApiOperation(value = "分页查询sku list")
    public Result onSale(@PathVariable Long skuId) {
        skuInfoService.onSale(skuId);
        return Result.ok();
    }
}
